<?php
/**
 * 销售排行
 * Enter description here ...
 * @author nijn
 *
 */
class SellRankingBehavior extends CActiveRecordBehavior {

	public function sellRanking() {
		$model = $this->owner;
		$criteria = $model->getDbCriteria();
		$criteria->join = 'LEFT JOIN order_item AS o ON (o.goods_id = t.id) LEFT JOIN `order` as r on (o.order_id = r.id)';
		$criteria->compare('r.status','ST_FINISHED');
		$criteria->group = 't.id';
		$criteria->order = 'SUM(o.item_num) DESC';
		$criteria->condition = preg_replace('/\w.object_type|object_type/', $model->tableAlias.'.object_type', $criteria->condition);
		return $model;
	}
}

?>